package com.cs.common;

import com.cs.enums.ResultCodeEnum;
/**
 * Created by IntelliJ IDEA.
 *
 * @author ouyangzhixiang
 * @date 2018/9/12
 */
public class Result<T> {
    private Integer status;

    private String msg;

    private T data;

    private Result(Integer status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    private Result(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public boolean isSuccess() {
        return this.status.equals(ResultCodeEnum.SUCCESS.getCode());
    }

    public static <T> Result<T> createBySuccess() {
        return new Result<>(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getDesc());
    }

    public static <T> Result<T> createBySuccessMessage(String msg) {
        return new Result<>(ResultCodeEnum.SUCCESS.getCode(), msg);
    }

    public static <T> Result<T> createBySuccess(T data) {
        return new Result<>(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getDesc(), data);
    }

    public static <T> Result<T> createBySuccessMessage(String msg, T data) {
        return new Result<>(ResultCodeEnum.SUCCESS.getCode(), msg, data);
    }

    public static <T> Result<T> createByError() {
        return new Result<>(ResultCodeEnum.ERROR.getCode(), ResultCodeEnum.ERROR.getDesc());
    }

    public static <T> Result<T> createByErrorMessage(String msg) {
        return new Result<>(ResultCodeEnum.ERROR.getCode(), msg);
    }

    public static <T> Result<T> createByErrorMessage(String msg, T data) {
        return new Result<>(ResultCodeEnum.ERROR.getCode(), msg, data);
    }

    public static <T> Result<T> createByErrorCodeMessage(int errorCode, String msg) {
        return new Result<>(errorCode, msg);
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }
}
